<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/comm/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="后台管理系统">
    <meta name="description" content="致力于提供通用版本后台管理解决方案">
    <link rel="shortcut icon" href="${ctx}/static/img/favicon.ico">
    <link rel="stylesheet" href="${ctx}/static/layui_v2/css/layui.css">
    <script src="${ctx}/static/layui_v2/layui.js"></script>
</head>
<body class="childrenBody" style="font-size: 12px;margin: 10px 10px 0;">
<form class="layui-form layui-form-pane">
    <input id="userId" name="userId" type="hidden" value="${user.userId}">
    <div class="layui-form-item">
        <label class="layui-form-label">当前密码</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input" name="password" lay-verify="required|password" maxlength="10" placeholder="请输入当前密码">
        </div>
        <label class="layui-form-label">修改密码</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input" id="editpwd" name="editpwd" lay-verify="required|editpwd" maxlength="10" placeholder="请输入修改密码">
        </div>
         <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input"  name="confirmpwd" lay-verify="required|confirmpwd" maxlength="10" placeholder="请输入确认密码">
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
           <button class="layui-btn" lay-submit="" lay-filter="editPwd">保存</button>
           <button type="layui-btn" id="cancle" class="layui-btn layui-btn-primary">取消</button>
    </div>
</form>
<script type="text/javascript">
    layui.config({
        base : "${ctx}/static/js/"
    }).use(['form','layer','jquery','common'],function(){
        var $ = layui.$,
                form = layui.form,
                common = layui.common,
                layer = parent.layer === undefined ? layui.layer : parent.layer;
        /**表单验证*/
        form.verify({
        	editpwd:[/(.+){6,12}$/, '密码必须6到12位'],
        	confirmpwd:function(value){
        		var repassvalue = $('#editpwd').val();
                if(value != repassvalue){
                   return '两次输入的密码不一致!';
                }
            }
        });

        //保存
        form.on("submit(editPwd)",function(data){
            var editPwdLoading = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            $.ajax({
                url : '${ctx}/user/edit_pwd.do',
                type : 'post',
                async: false,
                data : data.field,
                success : function(data) {
                    if(data.returnCode == 0000){
                        top.layer.close(editPwdLoading);
                    	window.top.location.href= "${ctx}/logout.do";
                    }else{
                        top.layer.close(editPwdLoading);
                        common.cmsLayErrorMsg(data.returnMessage);
                    }
                },error:function(data){
                    top.layer.close(index);
                }
            });
            return false;
        });

        //取消
        $("#cancle").click(function(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
    });
</script>
</body>
</html>